package collection.Stream;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

public class StreamApiDemo2 {
    public static void main(String[] args) {
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < 3; i++) {
            list.add((int) (Math.random() * 100));
        }
        System.out.println(list);

        Optional<Integer> value = list.stream().min((e1, e2) -> e1 - e2);
        System.out.println(value.get());

        value = list.stream().max((e1, e2) -> e1 - e2);
        System.out.println(value.get());

        boolean anyMatch = list.stream().anyMatch(e -> e % 2 == 0);
        System.out.println("是否有偶数:" + anyMatch);

        boolean allMatch = list.stream().allMatch(e -> e % 2 == 0);
        System.out.println("是否所有元素都是偶数:" + allMatch);

        boolean noneMatch = list.stream().noneMatch(e -> e % 2 == 0);
        System.out.println("是否没有偶数:" + noneMatch);

        int number = list.stream().reduce((e1, e2) -> e1 + e2).get();
        System.out.println("累加和:" + number);


    }
}
